package org.mayuanxiaonong.timserver.handler.deliver;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;

import org.mayuanxiaonong.timserver.packet.MessagePacket;
import org.mayuanxiaonong.timserver.packet.Packet;
import org.mayuanxiaonong.timserver.packet.PresencePacket;

/**
 * 分发队列
 * 
 * @author 9527
 *
 */
public class DeliverQueue {

	public static final BlockingQueue<Packet> MESSAGE_QUEUE = new LinkedBlockingQueue<Packet>();
	public static final BlockingQueue<Packet> PRESENCE_QUEUE = new LinkedBlockingQueue<Packet>();

	private static ExecutorService EXECUTOR = Executors.newCachedThreadPool();

	public static void deliver(MessagePacket packet)
			throws InterruptedException {
		MESSAGE_QUEUE.put(packet);
		EXECUTOR.execute(new MessageDeliver());
	}

	public static void deliver(PresencePacket packet)
			throws InterruptedException {
		PRESENCE_QUEUE.put(packet);
		EXECUTOR.execute(new PresenceDeliver());
	}

}
